package com.hrma.controller;

import com.github.pagehelper.Page;
import com.hrma.entity.*;
import com.hrma.services.SalaryLevelService;
import com.hrma.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/salaryLevel")
@Slf4j
public class SalaryLevelController {
    private final SalaryLevelService salaryLevelService;

    public SalaryLevelController(SalaryLevelService salaryLevelService) {
        this.salaryLevelService = salaryLevelService;
    }

    @PostMapping("/add")
    public Result<SalaryLevel> add(@RequestBody SalaryLevel data) {
        log.debug("收到add请求，请求参数：{}", data);
        return Result.ok(salaryLevelService.add(data));
    }

    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable int id) {
        log.debug("收到delete请求，请求参数：{}", id);
        salaryLevelService.delete(id);
        return Result.ok(null);
    }

    @PatchMapping("/update")
    public Result<?> update(@RequestBody List<SalaryLevelVO> data) {
        log.debug("收到update请求，请求参数：{}", data);
        salaryLevelService.update(data);
        return Result.ok(null);
    }

    @GetMapping("/select")
    public Result<List<SelectResult>> selectSalary() {
        log.debug("收到select请求!");
        return Result.ok(salaryLevelService.selectSalary());
    }

    @PostMapping("/list")
    public Result<ListWithCount<SalaryLevel>> getList(@RequestBody SalaryLevelDTO data) {
        log.debug("收到list请求，请求参数：{}", data);
        Page<SalaryLevel> res = salaryLevelService.getList(data);

        return Result.ok(new ListWithCount<>(res.getTotal(), res));
    }

    @GetMapping("/getSalaryLevel")
    public Result<List<SalaryLevelVO>> getSalaryLevel(){
        log.debug("收到getSalaryLevel请求!");
        return Result.ok(salaryLevelService.getSalaryLevel());
    }
}
